import { defineConfig, loadEnv } from "vite";
import path from "path";

function _resolve(dir) {
    return path.resolve(__dirname, dir)
}

export default defineConfig(({ mode, command }) =>({
    base: '/h5/xmedia',
    build: {
        // cssTarget: 'chrome40', // 注意添加css的低版本兼容，当然也可以配置PostCssPresetEnv
        target: 'es2015', // 使用esbuild将代码转换为ES5
        lib: {
            entry: path.resolve(__dirname, "./src/index.js"),
            name: "xmedia",
            fileName: (format) => `xmedia.${format}.js`
        },
        sourcemap: true,
        minify: "terser",
        terserOptions: {
            compress: {
                drop_console: command === "build",
                drop_debugger: command === "build"
            }
        }
    },
    resolve: {
        alias: {
            '@': _resolve('src'),
        },
    },
    server: {
        open: 'index.html',
    },
}));